package com.yunmang.fragment;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yunmang.R;
import com.yunmang.activity.TransportActivity;
import com.yunmang.activity.TransportDetailActivity;
import com.yunmang.activity.daohuo.ArriveActivity;
import com.yunmang.activity.exception.ExceptionManager;
import com.yunmang.activity.exception.ExceptionReportActivity;
import com.yunmang.activity.fache.TransportManager;
import com.yunmang.activity.kaipiaoActivity;
import com.yunmang.activity.ordermanager.OrderManagerActivity;
import com.yunmang.activity.qianshou.QianshouActivity;
import com.yunmang.activity.statictis.SavingQueryStatictics;
import com.yunmang.activity.statictis.SendStatictics;
import com.yunmang.activity.statictis.SignedStatics;
import com.yunmang.activity.trace.OrderTraceActivity;
import com.yunmang.adapter.MyHomeAdapter;
import com.yunmang.adapter.MyHomeAdapter2;
import com.yunmang.adapter.MyItemPagerAdapter;
import com.yunmang.adapter.MyPagerAdapter;
import com.yunmang.app.AppConstant;
import com.yunmang.entity.MyItemInfoBean;
import com.yunmang.utils.CommonUtils;
import com.yunmang.view.MyGridView;
import com.yunmang.view.ObservableScrollView;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者 : bean on 2017/4/5/0005.
 * 注释 :营运
 */
public class ServiceFragment extends BaseFragment {
    private ObservableScrollView scrollView;
    private LinearLayout llContainer;
    private ViewPager pager;
    private List<Integer> list = new ArrayList<>();
    private MyGridView gv_sy_item;
    private MyGridView gv_sy_item2;
    private List gvListItem = new ArrayList();
    private List<MyItemInfoBean> gvListItem2 = new ArrayList();
    private TextView tv_info;
    @Override
    public int getLayoutId() {
        return R.layout.fragment_service;
    }

    @Override
    public void initView(View view) {
        scrollView= (ObservableScrollView) view.findViewById(R.id.scrollView);
        llContainer= (LinearLayout) view.findViewById(R.id.ll_container);
        pager = (ViewPager) view.findViewById(R.id.vp_cycle);
        gv_sy_item = (MyGridView) view.findViewById(R.id.gv_sy_item);
        gv_sy_item2 = (MyGridView) view.findViewById(R.id.gv_sy_item2);
        tv_info= (TextView) view.findViewById(R.id.tv_depInfo);
        tv_info.setText(AppConstant.orgInfo.getName());
        llContainer.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
        llContainer.getBackground().setAlpha(0);
        scrollView.setScrollViewListener(new ObservableScrollView.ScrollViewListener() {
            @Override
            public void onScrollChanged(ObservableScrollView scrollView, int x, int y) {
                y = CommonUtils.px2Dp(context, y);
                if (y >= 0 && y < 256)
                    llContainer.getBackground().setAlpha(y);
            }
        });
        if (gvListItem2.size()<=0){
            initItem2Info();
        }

    }

    private void initItem2Info() {
        gvListItem2.add(new MyItemInfoBean(R.mipmap.bg_sy_sh,"发货统计","当日发货报表统计"));
        gvListItem2.add(new MyItemInfoBean(R.mipmap.bg_sy_th,"已提统计","当日已提报表统计"));
        gvListItem2.add(new MyItemInfoBean(R.mipmap.bg_sy_kc,"库存统计","当日库存报表统计"));
        gvListItem2.add(new MyItemInfoBean(R.mipmap.bg_sy_other,"其他统计","更多功能正在开发中"));
    }

    @Override
    public void initData() {
        pager.setAdapter(new MyItemPagerAdapter(getActivity(), list));
        gv_sy_item.setAdapter(new MyHomeAdapter(context));
        gv_sy_item2.setAdapter(new MyHomeAdapter2(context,gvListItem2));
    }

    @Override
    public void dealCommon() {
        super.dealCommon();
        gv_sy_item.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // todo 条目点击事件
                if(AppConstant.type.equals("2")){//分拨中心
                    switch (position){
                        case 0:
                            startActivity(new Intent(getActivity(), OrderManagerActivity.class));
                            break;
                        case 1:
                            startActivity(new Intent(getActivity(), ArriveActivity.class));
                            break;
                        case 2:
                            startActivity(new Intent(getActivity(), TransportActivity.class));
                            break;
                        case 3:
                            startActivity(new Intent(getActivity(), OrderTraceActivity.class));
                            break;
                        case 4:
                            startActivity(new Intent(getActivity(), ExceptionManager.class));
                            break;
                        case 5:
                            startActivity(new Intent(getActivity(), TransportManager.class));
                            break;
                    }
                }else if(AppConstant.type.equals("1")){//总公司 = 1,
                    switch (position){
                        case 0:
                            startActivity(new Intent(getActivity(), kaipiaoActivity.class));
                            break;
                        case 1:
                            startActivity(new Intent(getActivity(), TransportActivity.class));
                            break;
                        case 2:
                            startActivity(new Intent(getActivity(), ArriveActivity.class));
                            break;
                        case 3:
                            startActivity(new Intent(getActivity(), QianshouActivity.class));
                            break;
                        case 4:
                            startActivity(new Intent(getActivity(), OrderManagerActivity.class));
                            break;
                        case 5:
                            startActivity(new Intent(getActivity(), OrderTraceActivity.class));
                            break;
                        case 6:
                            startActivity(new Intent(getActivity(), ExceptionManager.class));
                            break;
                        case 7:
                            startActivity(new Intent(getActivity(), TransportManager.class));
                            break;
                    }
                }else{
                    switch (position){
                        case 0:
                            startActivity(new Intent(getActivity(), kaipiaoActivity.class));
                            break;
                        case 1:
                            startActivity(new Intent(getActivity(), TransportActivity.class));
                            break;
                        case 2:
                            startActivity(new Intent(getActivity(), ArriveActivity.class));
                            break;
                        case 3:
                            startActivity(new Intent(getActivity(), QianshouActivity.class));
                            break;
                        case 4:
                            startActivity(new Intent(getActivity(), OrderManagerActivity.class));
                            break;
                        case 5:
                            startActivity(new Intent(getActivity(), OrderTraceActivity.class));
                            break;
                        case 6:
                            startActivity(new Intent(getActivity(), ExceptionManager.class));
                            break;
                        case 7:
                            startActivity(new Intent(getActivity(), TransportManager.class));
                            break;
                    }
                }
            }
        });
        gv_sy_item2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position){
                    case 0:
                        startActivity(new Intent(getActivity(), SendStatictics.class));
                        break;
                    case 1:
                        startActivity(new Intent(getActivity(), SignedStatics.class));
                        break;
                    case 2:
                        startActivity(new Intent(getActivity(), SavingQueryStatictics.class));
                        break;
                    case 3:
//                        startActivity(new Intent(getActivity(), ExceptionManager.class));
                        showToast("该功能暂未开放");
                        break;
                    default:
                        break;
                }
            }
        });

    }
}
